<template>
  <div class="newsinfo-box">
    <h3>{{ newsInfo.title }}</h3>
    <div class="time-click">
      <span>发表时间: {{ newsInfo.add_time | dateFormat }}</span>
      <span>点击次数: {{ newsInfo.click }}次</span>
    </div>
    <hr>
    <div v-html="newsInfo.content"></div>
    <comment :id="this.id"></comment>
  </div>
</template>

<script>
import { Toast } from "mint-ui"
//导入评论子组件
import comment from '../common/comment.vue'
export default {
  data() {
    return {
      id: this.$route.params.id,
      newsInfo: []
    }
  },
  created() {
    this.getNewsInfo();
  },
  methods: {
    getNewsInfo() {
      this.$http.get("api/getnew/" + this.id).then(res => {
        if (res.body.status === 0) {
          this.newsInfo = res.body.message[0]
        } else {
          Toast("获取信息失败")
        }
      })
    }
  },
  components: {//用来注册子组件
    comment
  }
}
</script>

<style lang="scss">
.newsinfo-box {
  padding: 0 3px;
  h3 {
    font-size: 14px;
    color: red;
    text-align: center;
  }
  .time-click {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #26a2ff;
  }
}
</style>
